﻿@{
    Layout = null;
}

@* <!DOCTYPE html> *@

<html style="margin-top:200px">
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Login</title>
</head>
<body>
    @* <!DOCTYPE html> *@
    <html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Demo</title>
        <link href="~/layui/css/layui.css" rel="stylesheet" />
    </head>
    <body>
        <style>
            .demo-login-container {
                width: 320px;
                margin: 21px auto 0;
            }

            .demo-login-other .layui-icon {
                position: relative;
                display: inline-block;
                margin: 0 2px;
                top: 2px;
                font-size: 26px;
            }
        </style>
        <form class="layui-form">

            <div class="demo-login-container">
                <div class="layui-form-item">
                    <div style="text-align:center">
                        <h1>用户登录</h1>
                    </div><br />
                    <div class="layui-input-wrap">
                        <div class="layui-input-prefix">
                            <i class="layui-icon layui-icon-username"></i>
                        </div>
                        <input type="text" name="Name" value="" lay-verify="required" placeholder="用户名" lay-reqtext="请填写用户名" autocomplete="off" class="layui-input" lay-affix="clear">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-wrap">
                        <div class="layui-input-prefix">
                            <i class="layui-icon layui-icon-password"></i>
                        </div>
                        <input type="password" name="Pwd" value="" lay-verify="required" placeholder="密   码" lay-reqtext="请填写密码" autocomplete="off" class="layui-input" lay-affix="eye">
                    </div>
                    <div class="layui-form-item">
                        <input type="checkbox" name="remember" lay-skin="primary" title="记住密码">
                        <a href="#forget" style="float: right; margin-top: 7px;">忘记密码？</a>
                    </div>
                    <div class="layui-form-item">
                        <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="demo-login">登录</button>
                    </div>
                    <div class="layui-form-item demo-login-other">
                        <label>社交账号登录</label>
                        <span style="padding: 0 21px 0 6px;">
                            <a href="javascript:;"><i class="layui-icon layui-icon-login-qq" style="color: #3492ed;"></i></a>
                            <a href="javascript:;"><i class="layui-icon layui-icon-login-wechat" style="color: #4daf29;"></i></a>
                            <a href="javascript:;"><i class="layui-icon layui-icon-login-weibo" style="color: #cf1900;"></i></a>
                        </span>
                        或 <a href="javascript:;">注册帐号</a>
                    </div>
                </div>
        </form>

        <script src="~/layui/layui.js"></script>
        <script>
            layui.use(function () {
                var form = layui.form;
                var layer = layui.layer;
                var $ = layui.$;


                // 提交事件
                form.on('submit(demo-login)', function (data) {
                    var field = data.field; // 获取表单字段值

                    $.ajax({
                        url: "http://8.140.245.229:8000/AuthorizationSet/api/User/UserLogin",
                        type: 'post',
                        data: JSON.stringify(field),
                        contentType: 'application/json',
                        // headers: {
                        //     'Authorization': 'Bearer yourTokenHere'
                        // },
                        success: function (res) {
                            if (res.Id != 0) {
                                localStorage["token"] = res.token;
                                localStorage["userId"] = res.Id;

                                AddLogInfo("登录了系统","","")
                                
                                if (res.roleId == 1) {
                                    location.href = '/BasicData/SuperiorGrid'
                                } else if (res.roleId == 2) {
                                    location.href = '/BasicData/ExecutionGrid'
                                } else if (res.roleId == 3) {
                                    location.href = '/BasicData/GridInspector'
                                } else {
                                    layer.msg("账号或密码有误")
                                }
                            }
                        }
                    })


                    return false; // 阻止默认 form 跳转
                });




                //第一个参数为操作内容，例如：登录了系统，修改/删除/添加/查询了日志表（或其他表，每次调用根据进行的操作写）
                //第二个参数为修改专用，将修改前的参数转为json字符串格式传入
                //第三个参数是将添加或删除的数据转为json传入，若是修改方法则把修改后的数据转为json字符串传入
                function AddLogInfo(OperationalContext, PreOperation, AfterOperation) {
                    const data = {
                        olContext: OperationalContext,
                        PreOperation: PreOperation,
                        AfterOperation: AfterOperation
                    };
                    // alert(JSON.stringify(data));
                    $.ajax({
                        url: "http://8.140.245.229:8000/WorkBench/api/Log/AddLog",
                        type: 'post',
                        dataType: 'json',
                        headers: {
                            'Authorization': "Bearer " + localStorage["token"] + ""
                        },
                        contentType: 'application/json', // 添加正确的 Content-Type 头部
                        data: JSON.stringify(data),
                        success: function (res) {
                            // alert(res)
                            getListData(1);
                            console.log(res)
                        }
                    })
                }
            });
        </script>

    </body>
</html>
</body>
</html>
